import { createStore } from 'vuex'
import router from '@/router'
import qs from 'qs'

export default createStore({
  state: {
   token: '',
   currentLoginUser:'',
  },
  getters: {
    GET_TOKEN: state => {
      return sessionStorage.getItem("token")
    },
    GET_USERINFO:state=>{
      console.log("GET_USERINFO="+sessionStorage.getItem("userInfo"))
      return JSON.parse(sessionStorage.getItem("userInfo"))
    }
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      // state.token = token
      sessionStorage.setItem("token", token)
    },
    RESET_TOKEN:(state)=>{
      console.log("xxxx")
      //state.token=''
      sessionStorage.setItem("token", "")
    },
    SET_USERINFO:(state,userInfo)=>{
      console.log("xxx="+JSON.stringify(userInfo))
      sessionStorage.setItem("userInfo", JSON.stringify(userInfo))
    }
  },
  actions: {
    // 安全退出
    logout(){
      window.sessionStorage.clear();
      this.state.hasRoutes=false
      router.replace('/login')
    }
  },
  modules: {
  }
})
